<?php echo $this->render('/public/header'); ?>
<?php use yii\helpers\Url; ?>
<?php $info = $this->params['info']; ?>
    <div id="main" class="col-xs-12">
        <div class="col-xs-4">
            <a href="javascript:window.history.go(-1);" class="btn btn-success">返回</a>
            <div id="form">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">来源</label>
                    <div class="layui-input-block">
                        <select name="refer" class="form-control">
                            <?php foreach ($this->params['inquiryType'] as $v): ?>
                                <option value="<?php echo $v['id']; ?>" <?php if($info['refer']==$v['id']){echo 'selected';}?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">是否新客户</label>
                    <div class="layui-input-block">
                        <select class="form-control" name="inquiry_status">
                            <option value="1" <?php echo $info['inquiry_status']==1?'selected':'';?>>新客户</option>
                            <option value="2" <?php echo $info['inquiry_status']==2?'selected':'';?>>老客户</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">客户编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="customer_num" value="<?php echo $info['customer_num']; ?>"
                               lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">发询盘时间</label>
                    <div class="layui-input-block">
                        <input type="text" value="<?php echo date('Y-m-d H:i:s', $info['consultation_time']); ?>"
                               name="consultation_time"
                               onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                               required autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">回复时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="reply_time" value="<?php
                        if ($info['reply_time']) {
                            echo date('Y-m-d H:i:s', $info['reply_time']);
                        }
                        ?>" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">分配时间</label>
                    <div class="layui-input-block">
                        <input type="text" value="<?php
                        if ($info['dispatch_time']) {
                            echo date('Y-m-d H:i:s', $info['dispatch_time']);
                        }
                        ?>" name="dispatch_time"
                               onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">客户名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="<?php echo $info['name']; ?>" name="name" required
                               lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">国家</label>
                    <div class="layui-input-block">
                        <input type="text" name="country" value="<?php echo $info['country']; ?>" required
                               lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" value="<?php echo $info['email']; ?>" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">下单邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="order_email" value="<?php echo $info['order_email']; ?>"
                               lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">客户来源</label>
                    <div class="layui-input-block">
                        <select class="form-control" name="recommend">
                            <option value="0">请选择</option>
                            <?php foreach ($this->params['customerRefer'] as $v):?>
                                <option value="<?php echo $v['id'];?>" <?php if($v['id']==$info['recommend']){echo 'selected';}?>><?php echo $v['name'];?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">询盘内容</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="inquiry_detail"
                                  class="layui-textarea"><?php echo $info['inquiry_detail']; ?></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">询盘质量</label>
                    <div class="layui-input-block">
                        <select class="form-control" name="star" id="star">
                            <option value="1" <?php if ($info['star'] == 1) {
                                echo "selected";
                            } ?>>1星
                            </option>
                            <option value="2" <?php if ($info['star'] == 2) {
                                echo "selected";
                            } ?>>2星
                            </option>
                            <option value="3" <?php if ($info['star'] == 3) {
                                echo "selected";
                            } ?>>3星
                            </option>
                            <option value="4" <?php if ($info['star'] == 4) {
                                echo "selected";
                            } ?>>4星
                            </option>
                            <option value="5" <?php if ($info['star'] == 5) {
                                echo "selected";
                            } ?>>5星
                            </option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">业务员</label>
                    <div class="layui-input-block">

                        <select class="form-control" name="service_name" id="service_name">
                            <option value=0>--请选择--</option>
                            <?php if ($this->params['saleman']) { ?>
                                <?php foreach ($this->params['saleman'] as $k => $v) { ?>

                                    <option value="<?php echo $v['job_number']; ?>" <?php if ($info['service_name'] == $v['job_number']) {
                                        echo 'selected';
                                    }; ?>><?php echo $v['name']; ?></option>
                                <?php } ?>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:100px">状态</label>
                    <div class="layui-input-block">
                        <select class="form-control" name="status" id="status">
                            <option value="1" <?php if ($info['status'] == 1) {
                                echo "selected";
                            } ?>>待分配
                            </option>
                            <option value="2" <?php if ($info['status'] == 2) {
                                echo "selected";
                            } ?>>已分配
                            </option>
                            <option value="3" <?php if ($info['status'] == 3) {
                                echo "selected";
                            } ?>>拒绝
                            </option>
                        </select>
                    </div>
                </div>
            </div>
            <button type="submit" onclick="edit()" class="btn btn-success">修改</button>
        </div>
    </div>
    <script>
        function edit() {
            var data = {};
            $("#form").find("input").each(function (k) {
                data[$(this).attr('name')] = $(this).val();
            });
            data.status = $("#status").val();
            data.service_name = $("#service_name").val();
            data.star = $("#star").val();
            data.inquiry_detail = $("#inquiry_detail").val();
            data.refer = $("select[name=refer]").val();
            data.recommend = $("select[name=recommend]").val();
            data.inquiry_status = $("select[name=inquiry_status]").val();
            var id = <?php echo yii::$app->request->get('id');?>;
            if (layer.confirm('确认修改', {}, function () {
                    $.post('/setting/inquiry_edit_act', {
                        data: data,
                        id: id
                    }, function (res) {
                        if (res.code == 1) {
                            layer.confirm(res.msg, {}, function () {
                                window.location.reload();
                            })
                        } else {
                            layer.alert(res.msg);
                        }
                    }, 'json')
                })) ;

        }
    </script>
<?php echo $this->render('/public/footer'); ?>